Documentation for class menu

Inherits from 	window_object 

Properties declared in menu 
	action 
	attached_menu 
	cells 
	supermenu 
	target 

Class Methods declared in menu 
	new 

Methods declared in menu 
	action 
		size_to_fit 
	any 
		action 
		add_cell(cell) 
		attached_menu 
		cells 
		cell_at(index) 
		do_action 
		find_cell_with_tag(tag) 
		insert_cell_at(cell, index) 
		is_attached 
		is_torn_off 
		remove_cell_at(index) 
		set_action(message_name) 
		set_target(object) 
		size_to_fit 
		supermenu 
		target 
	events 
		do_action 
	get 
		action 
		attached_menu 
		cells 
		supermenu 
		target 
	set 
		set_action(message_name) 
		set_target(object) 

Class 
#begin_class
menu 
The class menu is a sub-class of the class window_object. 
A menu has a collection of menu cells. Each cell may have a sub-menu attached to it.
Every program has a menu called {menu main}. That is the menu that will be the main menu of the program when the program runs under CraftManEngine. In CraftMan the main menu of the current program can be found in the menu Current.
You may add items in the main menu by adding menu cells to it.
Ex:
To add an item "My Item" to the main menu:
c := {menu_cell}:new
c:set_title("My Item")
{menu main}:add_cell(c)

To add an item "My First Item" as the first item of the main menu:
c := {menu_cell}:new
c:set_title("My First Item")
{menu main}:insert_cell_at(c, 1)

To add a sub-menu to the first menu cell in the menu:
m := {menu}:new
{menu main}:cell_at(1):set_submenu(m)
#end_class

Properties 

#begin_property
action 
Stores the name of the action message that is used by the default implementation of the do_action method. The action message is sent to the object specified by the target property. 
See the do_action method description in control for details.
#end_property

#begin_property
attached_menu 
Stores a reference to the menu that might be attached to the menu.
#end_property

#begin_property
cells 
Stores a collection of all the menu cells of the menu.
#end_property

#begin_property
supermenu 
Stores a reference to the supermenu of the menu.
Note: The main menu does never have a supermenu.
#end_property

#begin_property
target 
Stores the reference to an object that receives the action message specified by the action property. When the menu receives a do_action message it sends the action message to the target. 
See the do_action method description in control for details.
#end_property

Methods 

#begin_method
action 
Returns the action property of the menu.
#end_method

#begin_method
add_cell(cell) 
Adds the menu cell cell at the end of the menu.
Returns self.
#end_method

#begin_method
attached_menu 
Returns the attached_menu property of the menu.
#end_method

#begin_method
cells 
Returns the cells property of the menu.
#end_method

#begin_method
cell_at(index) 
Returns the menu cell at index. 
The topmost menu cell has the index 1. 
Note:
{menu main}:cell_at(1)
is equivalent to
{menu main}:cells:at(1)
The first method does not generate garbage and will be faster. 
#end_method

#begin_method
do_action 
When the user selects a menu cell the system sends a do_action message to the that menu cell. 
If the action property of the menu cell is nil the menu cell passes the do_action message to the menu it is located in.
The default behavior of the do_action method in a menu is to send the message stored in the action property to the object referenced by the target property.
Returns self.
Comment: This method is not used very often. Usually you set the action and target properties of the menu cells to specify the behavior of a menu. 
You may override the default do_action behavior to get a specific behavior.
Note: If you want the action message to be sent to the target even when you override the do_action method, make sure the last line in your new do_action method is:
return super:do_action 
#end_method

#begin_method
find_cell_with_tag(tag) 
Returns the first cell in the collection of menu cells with the tag tag. If no such menu cell exists the method returns nil.
#end_method

#begin_method
insert_cell_at(cell, index) 
Inserts the menu cell cell at the position index in the menu.
Ex:
To add an item "My First Item" as the first item of the main menu:
c := {menu_cell}:new
c:set_title("My First Item")
{menu main}:insert_cell_at(c, 1)
Returns self.
#end_method

#begin_method
is_attached 
Returns true if the menu is attached to its supermenu. Otherwise it returns false.
#end_method

#begin_method
is_torn_off 
Returns true if the menu is torn off from its supermenu. Otherwise it returns false.
#end_method

#begin_method
remove_cell_at(index) 
Removes the menu cell at index. If index is lower than 1 or higher than the number of menu cells in the menu the method returns nil.
Returns self.
#end_method

#begin_method
set_action(message_name) 
Sets the action property to the symbol message_name. 
Returns self.
#end_method

#begin_method
set_target(object) 
Sets the target property to object. 
Returns self.
#end_method

#begin_method
size_to_fit 
Resizes the menu so that all its menu cells are large enough to hold their titles. 
Returns self.
Note: You only need to send this message if you have changed the title of a menu cell.
#end_method

#begin_method
supermenu 
Returns the supermenu property of the menu.
#end_method

#begin_method
target 
Returns the target property of the menu.
#end_method

Class Methods 

#begin_class_method
new 
Returns a new menu object.
Ex:
{menu}:new
#end_class_method